import 'package:basic_common/common_exports.dart';
import 'package:basic_widgets/app_bar_widget.dart';
import 'package:basic_widgets/text_widget.dart';
import 'sms_code_controller.dart';
import 'view/code_input_view.dart';

/// 输入验证码界面
class SmsCodePage extends GetView<SmsCodeController> {
  const SmsCodePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: backAppbar(),
      body: Container(
        color: Colors.white,
        height: ScreenHelper.screenHeight,
        padding: EdgeInsets.symmetric(horizontal: ScreenHelper.width(15)),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            SizedBox(
              height: ScreenHelper.height(40),
            ),
            norTitle(title: '请输入验证码', isBlod: true),
            Text(
              "我们将以短信的形式将验证码发送给您，请注意查收",
              style: TextStyle(fontSize: ScreenHelper.sp(13)),
              textAlign: TextAlign.left,
            ),
            // CodeInputContainer(
            //   count: 6,
            //   phone: '18888888888',
            //   onRestart: () async {
            //     Function() cancel = () => {ToastUtils.toast('取消')};
            //     await Future.delayed(const Duration(seconds: 1));
            //     cancel.call();
            //     ToastUtils.toast('验证码发送成功');
            //     return true;
            //   },
            //   onResult: (code) {
            //     ToastUtils.toast('验证码（$code）错误');
            //   },
            // )
            CodeInputContainer(
              count: 4,
              phone: '',
              onRestart: () async {
                Function() cancel = () => {ToastUtils.toast('取消')};
                await Future.delayed(const Duration(seconds: 1));
                cancel.call();
                controller.getSmsCode();
                ToastUtils.toast('验证码发送成功');
                return true;
              },
              onResult: (code) {
                if (controller.type.value == 1) {
                  controller.loginBySmsCode(code);
                } else if (controller.type.value == 2) {
                  controller.validSmsCode(code);
                }
                // ToastUtils.toast('验证码（$code）错误');
              },
            )
          ],
        ),
      ),
    );
  }
}
